package com.doit.day02;

import com.alibaba.fastjson.JSON;
import com.doit.day01.JedisUtil;
import redis.clients.jedis.Jedis;
import redis.clients.jedis.JedisPool;
import redis.clients.jedis.Pipeline;
import redis.clients.jedis.Response;

import java.sql.*;
import java.util.List;

public class _03_mysql2redis {
    public static void main(String[] args) throws Exception {
        Connection conn = DriverManager.getConnection("jdbc:mysql://localhost:3306/test", "root", "123456");
        PreparedStatement pps = conn.prepareStatement("select * from user_info");
        ResultSet resultSet = pps.executeQuery();
        UserInfo userInfo = new UserInfo();

        Jedis jedis = JedisUtil.getJedis();

        Pipeline pipelined = jedis.pipelined();

        while (resultSet.next()){
            int id = resultSet.getInt("id");
            String name = resultSet.getString("name");
            int age = resultSet.getInt("age");
            String gender = resultSet.getString("gender");
            userInfo.setAge(age);
            userInfo.setId(id);
            userInfo.setName(name);
            userInfo.setGender(gender);
            String json = JSON.toJSONString(userInfo);
            pipelined.hset("mysql",id+"",json);
        }


        pipelined.syncAndReturnAll();


    }
}
